package jmine.tec.persist.schema.impl.parsers;

import java.util.regex.Matcher;

import jmine.tec.persist.schema.impl.elements.PrimaryKeyElement;
import jmine.tec.persist.schema.impl.elements.Schema;

/**
 * Parser de primary keys anônimas declaradas dentro do create table
 * 
 * @author lundberg
 */
public class PrimaryKeyTableParser extends AbstractSchemaElementParser<PrimaryKeyElement> {

    private static final int PK_COLUMNS_GROUP_INDEX = 1;

    /**
     * Construtor
     * 
     * @param schema schema
     */
    public PrimaryKeyTableParser(Schema schema) {
        super("primary\\s+key\\s+\\(([\\w\\s,]+)\\)", schema);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected PrimaryKeyElement doParse(Matcher matcher) {
        String[] columns = matcher.group(PK_COLUMNS_GROUP_INDEX).replaceAll("\\s", "").split(",");
        return new PrimaryKeyElement(columns, this.getSchema());
    }
}
